<?php
include_once "../header1.php";
?>
<script type="text/javascript" src="popup-window.js"></script>
<?php
include_once ("../Login/databaseconnection.php");

if(!loggedin())
{
	require_once ("../index.php");
}
   
   else
   {
   ?>
</head>
<body>
<?php
if(isset($_POST['submit']))
{
	require_once 'csvread.php';
}
?>
<?php
include_once "../header2.php";
?>
<?php
include_once "topmenu.php";
?>
<div id="content">
	<div id="main">
	  <div id="bodyfield">
<br/>

<div id="lefttablereg"><table width="398" height="263" border="0" class="tablefontv">
    <tr>
      <td height="24" colspan="3" class="err">
	  <?php
 include_once ("../uploerror.php");
 if(isset($_SESSION['errorinuploading']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errorinuploading'];
unset($_SESSION['errorinuploading']);
}
if(isset($_SESSION['errordata']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['errordata'];
unset($_SESSION['errordata']);
}
if(isset($_SESSION['errorexi']))
{
echo $_SESSION['errorexi'];
unset($_SESSION['errorexi']);
}
if(isset($_SESSION['insertsucc']))
{
echo '<img src="../images/alert.jpg" width="12" height="12"/>';
echo $_SESSION['insertsucc'];
unset($_SESSION['insertsucc']);
}
?></td>
      
    </tr>
    <tr>
      <td height="210" colspan="3"><h3>A&nbsp;<strong>school</strong>&nbsp;is an&nbsp;institution</a>&nbsp;designed  for the teaching of&nbsp;students</a>&nbsp;(or "pupils") under the direction of teachers&nbsp;. Most countries have systems of formal education, which is commonly Compulsory . In these systems,  students progress through a series of schools. That is why The details of schools in our department accessed by  this page...</h3></td>
     
    </tr>
    <tr>
      <td width="154">&nbsp;</td>
      <td width="110">&nbsp;</td>      
      <td width="120">
      <?php
	 if($_SESSION['Access_Type']=="Teacher in Charge"||$_SESSION['Access_Type']=="Teacher")
{
$School_Id=$_POST['School_Id'];
   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   $parameter=$Own_School_Id.",School_Id";
      ?>
      <a href="../quick_search.php?q=<?php echo $parameter; ?>&a=<?php echo $_SESSION['Access_Type'];?>" target="_blank" class="link_anchor">Quick Search</a>
      <?php
	  }
}
 if($_SESSION['Access_Type']=="Administrator")
{
	 $get_Sch=mysql_query("SELECT * FROM school");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $School_Id=$rowsch['School_Id'];
   $parameter=$School_Id.",School_Id";
}
	?>
    <a href="../quick_search.php?q=<?php echo $parameter; ?>&a=<?php echo $_SESSION['Access_Type'];?>" target="_blank" class="link_anchor">Quick Search</a>
    <?php
}
      ?></td>
    </tr>
    </table>
</div><div id="righttablereg">
    <?php  
  $Sch_Ids="";
  $L_Sch_Ids="";
   $all_labs=mysql_query("SELECT * FROM lab");
  while($a_labs=mysql_fetch_array($all_labs))
  {
	$School_Id=$a_labs['School_Id'];
		 $che_labs=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id'");
	 if(!$che_labs||mysql_num_rows($che_labs)==0)
	 {
		if(empty($L_Sch_Ids))
		{
			$L_Sch_Ids=$School_Id;
		}
		else
		{
		$exist="No";
		$All_L_Sch_Ids=explode(",",$L_Sch_Ids);
		for($i=0;$i<count($All_L_Sch_Ids);$i++)
		{
		if($School_Id==$All_L_Sch_Ids[$i])
		{
		$exist="Yes";
		break;
		}
		}
		if($exist=="No")
		{
			$L_Sch_Ids=$L_Sch_Ids.",".$School_Id;
			}
		}
	 }
  }
  $all_teachers=mysql_query("SELECT * FROM teacher");
  while($a_teachers=mysql_fetch_array($all_teachers))
  {
	$School_Id=$a_teachers['School_Id'];
		 $che_Sch=mysql_query("SELECT * FROM school WHERE School_Id='$School_Id'");
	 if(!$che_Sch||mysql_num_rows($che_Sch)==0)
	 {
		if(empty($Sch_Ids))
		{
		$exist="No";
		$All_La_Sch_Ids=explode(",",$L_Sch_Ids);
		for($i=0;$i<count($All_La_Sch_Ids);$i++)
		{
		if($School_Id==$All_La_Sch_Ids[$i])
		{
		$exist="Yes";
		break;
		}
		}
		if($exist=="No")
		{
			$Sch_Ids=$School_Id;
			}
		}
		else
		{
		$exist="No";
		$All_Sch_Ids=explode(",",$Sch_Ids);
		for($i=0;$i<count($All_Sch_Ids);$i++)
		{
		if($School_Id==$All_Sch_Ids[$i])
		{
		$exist="Yes";
		break;
		}
		else
		{
		$All_La_Sch_Ids=explode(",",$L_Sch_Ids);
		for($i=0;$i<count($All_La_Sch_Ids);$i++)
		{
		if($School_Id==$All_La_Sch_Ids[$i])
		{
		$exist="Yes";
		break;
		}
		}
		}
		}		
		if($exist=="No")
		{
			$Sch_Ids=$Sch_Ids.",".$School_Id;
		}
		}
	 }
  }
  if(empty($Sch_Ids))
  {
   $NR_Sch_Ids=$L_Sch_Ids;
  }
  if(empty($L_Sch_Ids))
  {
   $NR_Sch_Ids=$Sch_Ids;
  }
  else
  {
  $NR_Sch_Ids=$Sch_Ids.",".$L_Sch_Ids;
  } 
  if($NR_Sch_Ids!="")
  {
$Schoo_Ids=explode(",",$NR_Sch_Ids);
if($_SESSION['Access_Type']=="Teacher in Charge")
	   {
	   $NIC_Number=$_SESSION['NIC_Number'];
   $get_Sch=mysql_query("SELECT * FROM teacher WHERE T_NIC_Number='$NIC_Number'");
   if($rowsch=mysql_fetch_array($get_Sch))
{
   $Own_School_Id=$rowsch['School_Id'];
   }
   if($Own_School_Id=="")
    {
	   ?>
  <img src="<?php echo "$basedir";?>/images/Schoolimage.jpg" width="550" height="370" alt="School" style="border: solid 1px #D6E0E2; box-shadow: inset 0px 0px 0px 1px #fff; border: 0; -webkit-box-shadow:	inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); -moz-box-shadow: inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); box-shadow: inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px;"/>
  <?php
	   }
   if($Own_School_Id!="")
   {
   $c_sch=mysql_query("SELECT * FROM school WHERE School_Id='$Own_School_Id'");
	   if(mysql_num_rows($c_sch)==0)
	   {
echo '<table border="1" class="tablefontv">';
  echo '<tr bgcolor="#333333"><td><font color="white">School Id</font></td><td></td></tr>';
  for($i=0;$i<count($Schoo_Ids);$i++)
  {
  $S_Id=$Schoo_Ids[$i];
if($S_Id!="")
{
	  if(is_int($i/2))
    {
   $color="#999999";
    }
	else
	{
   $color="#CCCCCC";
    }
	
$get_sch=mysql_query("SELECT * FROM teacher WHERE School_Id='$S_Id'");
if(mysql_num_rows($get_sch)>0)
{
	   if($get_sch_row=mysql_fetch_array($get_sch))
	   {
	    
	   if($get_sch_row['School_Id']==$Own_School_Id)
	   {
	   echo '<tr bgcolor="'.$color.'"><td>'.$get_sch_row['School_Id'].'</td><td><a href="AddSch.php?School_Id='.$get_sch_row['School_Id'].'">Edit</a></td></tr>';
	  }	  
	}  
} 
}
else
{  
$get_lab_sch=mysql_query("SELECT * FROM lab WHERE School_Id='$S_Id'");
if($get_lab_sch)
{
	   if($get_lab_sch_row=mysql_fetch_array($get_lab_sch))
	   {
	    
	   if($get_lab_sch_row['School_Id']==$Own_School_Id)
	   {
	   echo '<tr bgcolor="'.$color.'"><td>'.$get_lab_sch_row['School_Id'].'</td><td><a href="AddSch.php?School_Id='.$get_lab_sch_row['School_Id'].'">Edit</a></td></tr>';
	  }	  

}	}  
} 	      
  }
  echo '</table>';  
  }
  if(mysql_num_rows($c_sch)>0)
	   {
	   ?>
  <img src="<?php echo "$basedir";?>/images/Schoolimage.jpg" width="550" height="370" alt="School" style="border: solid 1px #D6E0E2; box-shadow: inset 0px 0px 0px 1px #fff; border: 0; -webkit-box-shadow:	inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); -moz-box-shadow: inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); box-shadow: inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px;"/>
  <?php
	   }
  }
  }
   else if($_SESSION['Access_Type']=="Administrator")
	   {
echo '<table border="1" class="tablefontv">';
  echo '<tr bgcolor="#333333"><td><font color="white">School Id</font></td><td></td></tr>';
  for($i=0;$i<count($Schoo_Ids);$i++)
  {
$S_Id=$Schoo_Ids[$i];
if($S_Id!="")
{
	  if(is_int($i/2))
    {
   $color="#999999";
    }
	else
	{
   $color="#CCCCCC";
    }

	$get_sch=mysql_query("SELECT * FROM teacher WHERE School_Id='$S_Id'");
if(mysql_num_rows($get_sch)>0)
{
	   if($get_sch_row=mysql_fetch_array($get_sch))
	   {
	  echo '<tr bgcolor="'.$color.'"><td>'.$get_sch_row['School_Id'].'</td><td><a href="AddSch.php?School_Id='.$get_sch_row['School_Id'].'">Edit</a></td></tr>';
	   }
}
else
{
$get_lab_sch=mysql_query("SELECT * FROM lab WHERE School_Id='$S_Id'");
if($get_lab_sch)
{
	   if($get_lab_sch_row=mysql_fetch_array($get_lab_sch))
	   {
	  echo '<tr bgcolor="'.$color.'"><td>'.$get_lab_sch_row['School_Id'].'</td><td><a href="AddSch.php?School_Id='.$get_lab_sch_row['School_Id'].'">Edit</a></td></tr>';
	   }
}
}
	   	 }
}
		 echo '</table>'; 
}	
}	 
 if($NR_Sch_Ids==""||$_SESSION['Access_Type']=="Teacher")
  {
   ?>
  <img src="<?php echo "$basedir";?>/images/Schoolimage.jpg" width="550" height="370" alt="School" style="border: solid 1px #D6E0E2; box-shadow: inset 0px 0px 0px 1px #fff; border: 0; -webkit-box-shadow:	inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); -moz-box-shadow: inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); box-shadow: inset 0px 1px 0px #fff, 0px 1px 1px rgba(0,0,0,.15); -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px;"/>
  <?php
  }
  ?>
    </div>

    </div>
</div>
</div>
<div id="sidebar">
<br/>
<div id="partners" class="boxed">
			<h2 class="title">SCHOOLS</h2>
            </div>
                   <?php
 include_once ("uploform.php");
?>
<?php
include_once "menu.php";
?>
 <?php
include_once "../footer.php";
}
?>
</body>
</html>